package com.wly.dbc.parser;

import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import com.wly.datapool.skillpool.SkillPool;
import com.wly.datapool.skillpool.skill.SkillStatic;
import com.wly.define.IDZoneDefine;
import com.wly.define.ParserDefine;

public class SkillParser extends BaseParser
{

	SkillPool _skillPool = SkillPool.getInstance();
	@Override
	public int getParserId()
	{
		return ParserDefine.SKILL_PARSER;
	}

	@Override
	public String getXmlFileName()
	{
		return "skill.xml";
	}

	@Override
	public void doParser(Document doc)
	{
		// TODO Auto-generated method stub
		try
		{
			SkillStatic skill;
			NodeList nl = doc.getElementsByTagName("skill");
			Node nodeTmp;
			NamedNodeMap attrs;
			for (int i = 0; i < nl.getLength(); i++)
			{
				skill = new SkillStatic();
				attrs = nl.item(i).getAttributes();
				skill.skillId   = Integer.parseInt(attrs.getNamedItem("id").getNodeValue())+IDZoneDefine.SKILL_START_ID;
				skill.skillName = attrs.getNamedItem("name").getNodeValue();
				//skill.skillDesc = attrs.getNamedItem("").getNodeValue();
				skill.skillResult1 = Integer.parseInt(attrs.getNamedItem("skillResult1").getNodeValue());
				skill.skillResult2 = Integer.parseInt(attrs.getNamedItem("skillResult2").getNodeValue());
				skill.probability  = Integer.parseInt(attrs.getNamedItem("probability").getNodeValue());
				skill.attackTarget = Integer.parseInt(attrs.getNamedItem("attackTarget").getNodeValue());
				skill.isAttack     = Integer.parseInt(attrs.getNamedItem("attackOrDefenceSkill").getNodeValue());
				skill.soldierSelfReq = Integer.parseInt(attrs.getNamedItem("needSelfSoldierType").getNodeValue());
				skill.soldierEnemyReq= Integer.parseInt(attrs.getNamedItem("needEnemySoldierType").getNodeValue());
				_skillPool.addSkill(skill);
			}
		} 
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}

}
